from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import redirect

# Create your views here.
from app_1.models import User
from app_1.models import History


def index(request):
    return HttpResponse("hello!")


# 再这个
def info_list(request):
    data_list = User.objects.all
    print(data_list)
    return render(request, "info_list.html", {"data_list": data_list})


# 先这个
def info_add(request):
    if request.method == "GET":
        return render(request, 'info_add.html')
    user = request.POST.get("user")
    pwd = request.POST.get("pwd")
    User.objects.create(account=user, password=pwd)

    return redirect("/info/list")


def info_delete(request):
    nid = request.GET.get('nid')
    User.objects.filter(id=nid).delete()
    return redirect("/info/list")